﻿Chenxin.UI.ContractMgr=Chenxin.extend(Chenxin.UI.PageCommon,{
	actionUrl:'/service/logic/ContractMgr.ashx',
	initEvent:function(){
		var _this=this;
		$('#btn_edit').click(function(){
			if(!_this.currentId){
				alert('请选择一条记录！');
				return false;
			}
			window.location.href='/page/ContractInfo/ContractInfo.aspx?contract_id='+_this.currentId;
		});
		
		$('#btn_destory').click(function(){
			_this.changeStatus(0);
		});
		
		$('#btn_print').click(function(){
			if(!_this.currentId){
				alert('请选择一条记录！');
				return false;
			}
			if(_this.grid.getCurrentField('Contract_Status')==0){
				alert('此合同已经作废，不能执行此操作！');
				return false;
			}
			window.location.href='/page/ContractInfo/ContractViewPrint.aspx?contract_id='+_this.currentId;
		});
	},
	changeStatus:function(status){
		if(this.grid.getCurrentField('Contract_Status')==status){
			alert('此合同已经作废，不能执行此操作！');
			return;
		}
		this.del('changestatus',status==0?'确定作废这条合同记录吗？':'确定恢复这条合同记录吗？','',{status:status});
	},
	createGrid:function(){
		return new Chenxin.UI.JsonGrid({
			actionUrl:this.actionUrl+'?op=getlist',
			scope:this,
			renderTo:'contract_datalist',
			modelId:'Contract_Id',
			title:'成交合同列表',
			columns:{
				Contract_Id:{
					head:'id',
					create:false
				},
				Contract_Type:{
					head:'合同类型',
					width:80,
					sortable:true,
					renderer:function(val){
						if(val==10){
							return '居住用房';
						}
						return '非居住用房';
					}
				},
				Contract_Code:{
					head:'预成交编号',
					width:120,
					sortable:true
				},
				CityId:{
					head:'城市ID',
					width:80,
					create:false
				},
				CityName:{
					head:'成交城市',
					width:80,
					sortable:true
				},
				CompanyId:{
					head:'公司ID',
					width:80,
					sortable:true,
					create:false
				},
				CompanyName:{
					head:'成交公司',
					width:80,
					sortable:true
				},
				Contract_A:{
					head:'甲方',
					width:80
				},
				Contract_B:{
					head:'乙方',
					width:80
				},
				Contract_Date:{
					head:'录入日期',
					width:80,
					sortable:true,
					renderer:function(val){
						return val.substr(0,10);
					}
				},
				Contract_PrintCount:{
					head:'打印次数',
					width:60,
					sortable:true,
					renderer:function(val){
						return (val||0)+'次';
					}
				},
				Contract_Status:{
					head:'状态',
					width:80,
					sortable:true,
					renderer:function(val){
						if(val==0){
							return '<span style="color:#ff0000;">已作废</span>';
						}
						return '<span style="color:#00ff00;">正常</span>';
					}
				}
			}
		})
	},
	createSearch:function(){
		return new Chenxin.UI.ContractSearch({
			scope:this
		});
	},
	initComponent:function(){
		Chenxin.UI.ContractMgr.superclass.initComponent.call(this);
	}
});

Chenxin.UI.ContractSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
	id: 'contractinfo_search',
    initEvent: function() {
        var _this = this;
        $('#btnSearch').click(function() {
            _this.scope.reloadGrid();
        });
    },
    createComboList: function() {
		var _this=this;
		//城市
        var city = new Chenxin.UI.StructCombo({
            param: { op: 'getcity' },
            containerId: '#x_search_city',
            name: 'cityid',
            tbxWidth: 42,
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    company.clearItems();
                } else {
                    company.param.fatherid = this.getValue();
                    company.reload();
                }
				company.clearItems();
            }
        });

        //公司
        var company = new Chenxin.UI.StructCombo({
            autoLoad: false,
            param: { op: 'getcompany' },
            name: 'companyid',
            containerId: '#x_search_company',
            tbxWidth: 42
        });
		
		var type=new Chenxin.UI.Combo({
            containerId: '#x_search_contract_type',
            name: 'contract_type',
			items:[{txt:'居住用房',val:'10'},{txt:'非居住用房',val:'20'}],
            tbxWidth: 42
		});
		
		var status=new Chenxin.UI.Combo({
            containerId: '#x_search_status',
            name: 'contract_type',
			items:[{txt:'正常',val:'10'},{txt:'已作废',val:'0'}],
            tbxWidth: 42
		});
		
		return [city,company,type,status];
    },
    initComponent: function() {
        Chenxin.UI.ContractSearch.superclass.initComponent.call(this);
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function(){
	var cm=new Chenxin.UI.ContractMgr();
});